<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Builds and solves a simple least-squares problem using cvx</title>
<link rel="canonical" href="/Users/mcgrant/Projects/CVX/examples/html/simple_LS.html">
<link rel="stylesheet" href="../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Builds and solves a simple least-squares problem using cvx</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
echo <span class="string">on</span>

n = 100;
A = randn(2*n,n);
b = randn(2*n,1);
cvx_begin
   variable <span class="string">x(n)</span>
   minimize( norm( A*x-b ) )
cvx_end

echo <span class="string">off</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
n = 100;
A = randn(2*n,n);
b = randn(2*n,1);
cvx_begin
   variable x(n)
   minimize( norm( A*x-b ) )
cvx_end
 
Calling SDPT3 4.0: 201 variables, 101 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 101
 dim. of socp   var  = 201,   num. of socp blk  =  1
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|6.6e+00|1.4e+00|2.5e+02| 0.000000e+00  0.000000e+00| 0:0:00| chol  1  1 
 1|0.941|1.000|3.9e-01|6.3e-03|2.6e+01|-1.275650e+01 -2.180124e+01| 0:0:00| chol  1  1 
 2|1.000|1.000|7.7e-08|6.3e-04|2.1e+00|-1.004066e+01 -1.215678e+01| 0:0:00| chol  1  1 
 3|0.987|0.985|1.9e-08|7.1e-05|3.0e-02|-1.087762e+01 -1.090664e+01| 0:0:00| chol  1  1 
 4|0.989|0.989|6.0e-09|7.0e-06|3.3e-04|-1.088953e+01 -1.088975e+01| 0:0:00| chol  1  1 
 5|0.989|0.989|6.5e-11|7.8e-08|3.7e-06|-1.088966e+01 -1.088966e+01| 0:0:00| chol  1  1 
 6|0.989|0.989|7.2e-13|8.7e-10|4.1e-08|-1.088966e+01 -1.088966e+01| 0:0:00|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   =  6
 primal objective value = -1.08896629e+01
 dual   objective value = -1.08896629e+01
 gap := trace(XZ)       = 4.07e-08
 relative gap           = 1.79e-09
 actual relative gap    = 1.18e-09
 rel. primal infeas (scaled problem)   = 7.18e-13
 rel. dual     "        "       "      = 8.70e-10
 rel. primal infeas (unscaled problem) = 0.00e+00
 rel. dual     "        "       "      = 0.00e+00
 norm(X), norm(y), norm(Z) = 1.4e+00, 1.1e+01, 1.5e+01
 norm(A), norm(b), norm(C) = 1.4e+02, 2.0e+00, 1.6e+01
 Total CPU time (secs)  = 0.11  
 CPU time per iteration = 0.02  
 termination code       =  0
 DIMACS: 7.2e-13  0.0e+00  3.3e-09  0.0e+00  1.2e-09  1.8e-09
-------------------------------------------------------------------
 
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +10.8897
 

echo off
</pre>
</div>
</body>
</html>